import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/components/back_btn_icon.dart';
import 'package:share_fit/app/controllers/space/setting/setting_unit_logic.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/tools/color_const.dart';
import 'package:share_fit/app/ute/uteped_const.dart';
import 'package:share_fit/generated/locales.g.dart';
import 'package:sprintf/sprintf.dart';

class AboutPage extends StatelessWidget {

  final logic = Get.put(SettingLogic());

  @override
  Widget build(BuildContext context) {
    Map appInfo = logic.read(UTEPedConst.keyAppInfo, defaultValue: [], global: true);
    return Scaffold(
      // backgroundColor: Color(0xFFF5F9FB),
      appBar: AppBar(
        // backgroundColor: Color(0xFFF5F9FB),
        title: Text(LocaleKeys.setting_about.ts, style: TextStyle(fontSize: 54.sp, color: ColorConst.btnFontColor),),
        centerTitle: true,
        leading: BackBtnIcon(onTap: () => Get.back()),
        // leading: IconButton(
        //   padding: EdgeInsets.only(left: 15,),
        //   icon: Image.asset("assets/images/space/icon_appbar_arrow_back.png"),
        //   onPressed: () { Get.back(); },
        // ),
        // leadingWidth: 25,
      ),
      body: Container(
        constraints: BoxConstraints(
          minWidth: double.infinity
        ),
        margin: EdgeInsets.only(top: 304.h),
        child: Column(
          children: [
            Container(
              alignment: Alignment.center,
              width: 339.w,
              height: 270.h,
              child: Image.asset('assets/images/home/ic_launcher.png'),
            ),
            SizedBox(height: 155.h),
            _buildAppInfo(appInfo),
          ],),
        // child: FutureBuilder<AppInfo>(
        //   future: InstalledApps.getAppInfo(appInfo['packageName']),
        //   builder:
        //       (BuildContext buildContext, AsyncSnapshot<AppInfo> snapshot) {
        //     return snapshot.connectionState == ConnectionState.done
        //         ? snapshot.hasData
        //         ?Column(
        //           children: [
        //             Container(
        //               alignment: Alignment.center,
        //               width: 339.w,
        //               height: 270.h,
        //               child: Image.memory(snapshot.data!.icon!),
        //             ),
        //             SizedBox(height: 155.h),
        //             _buildAppInfo(snapshot.data!.name!, snapshot.data!.versionName!),
        //           ],)
        //         : _buildAppInfo('', '')
        //         : Center();
        //   },),
      ),
    );
  }

  Widget _buildAppInfo(appInfo) {
    String appName = appInfo['appName'];
    String versionName = sprintf("%s.%s", [appInfo['versionName'], appInfo['versionCode']]);

    Widget widget = Container(
      child: Column(
        children: [
          Text(appName, style: TextStyle(fontSize:54.sp, color: ColorConst.btnFontColor),),
          Text('${LocaleKeys.setting_about_version.ts} $versionName', style: TextStyle(fontSize:54.sp, color: ColorConst.btnFontColor),),
        ],
      ),
    );
    return widget;
  }

}